--
-- Author: yawei.zhu
-- Date: 2018-10-05 11:27:43
--
-- GoddessWishController
--

local GoddessWishView = import("..views.GoddessWishView")

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ControllerBase)

function ClassRef:ctor(data)
    self.super.ctor(self, data)
end

function ClassRef:init()
    self._model = app:getInst("BossModel")
end

function ClassRef:removeListeners()
    self.super.removeListeners(self)
end

function ClassRef:onEvent(eventName, data)
end

function ClassRef:listEvent()
    return {}
end


function ClassRef:openView(data)
    if not data then return end

    if cc.isDead(self._view) then
        self._view = GoddessWishView.new(app.mvc.VIEWTYPE_BLUR)
        self._view:onCloseView(handler(self, self.closeView))
        self._view:onClearView(handler(self, self.clearView))
        self._view:onOperate(handler(self, self.onOperate))
        self:addChild(self._view)
    end

    self._view:show()
    scheduler.newCron(function()
        self._view:updateView(data)
    end, 0.5)
end
function ClassRef:closeView(data)
    if self._view then
        self:removeChild(self._view, data)
        self:clearView()
    end
end
function ClassRef:clearView()
    if self._view then
        self._view = nil
    end
end

-------------------------------------------------------
function ClassRef:onOpenCardSuccess(index, info)
    if not self:isViewAlive() then return end
    self._view:onOpenCardSuccess(index, info)
end

function ClassRef:revertGoddessStatus()
    if not self:isViewAlive() then return end
    self._view:revertGoddessStatus()
end

function ClassRef:onNotifyMysteryReward(cardId)
    if not self:isViewAlive() then return end
    self._view:onNotifyMysteryReward(cardId)
end

-------------------------------------------------------
function ClassRef:onOperate(op, data)
    print("GoddessWishController:onOperate op = " .. op)
    if op == "onSelectCard" then
        self._model:reqGoddessOpenCard(data[1], data[2])
    end
end

return ClassRef
